Use host.getType() to detect the transport and branch accordingly. Each transport has its own error format: HTTP uses res.status().json(), WebSocket emits an error event to the socket client, and RPC returns a throwError observable. Throw the transport-appropriate exception in each branch.
HTTP — use host.switchToHttp().getResponse().status().json() for standard REST error responses.
WebSocket — use host.switchToWs().getClient().emit('exception', ...) to send the error to the socket.
RPC — return a throwError() observable; the microservice framework handles serialization.
WsException from @nestjs/websockets should be thrown in WebSocket context for proper formatting.
A single filter registered globally can handle all transports by branching on host.getType().